using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace CKS.EBE
{
    public class ErrorHandler : IHttpModule
    {
        #region IHttpModule Members

        public void Dispose()
        {
        }

        public void Init(HttpApplication context)
        {
            context.EndRequest += new EventHandler(context_EndRequest);
            context.Error += new EventHandler(context_Error);
            context.BeginRequest += new EventHandler(context_BeginRequest);
            context.Disposed += new EventHandler(context_Disposed);
            context.ReleaseRequestState += new EventHandler(context_ReleaseRequestState);
        }

        void context_ReleaseRequestState(object sender, EventArgs e)
        {
            
        }

        void context_Disposed(object sender, EventArgs e)
        {
            
        }

        void context_BeginRequest(object sender, EventArgs e)
        {
            
        }



        void context_Error(object sender, EventArgs e)
        {
            
        }

        void context_EndRequest(object sender, EventArgs e)
        {
            HttpContext ctx = HttpContext.Current;
            if (ctx.Response.StatusCode == 404 && ctx.Request.RawUrl.ToLower() != "/notfound.aspx")
            {
                // Handle page not found
                HttpContext.Current.Response.Redirect("/NotFound.aspx");
            }
        }

        #endregion
    }
}
